<template>
  <NavBarHeader />
  <p class="form-row-title">管理员登录</p>
  <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
        v-model="username"
        name="id"
        label="账号"
        placeholder="账号"
        autoComplete=“true”
        :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="pd"
        label="密码"
        placeholder="密码"
        autoComplete=“true”
        :rules="[{ required: true, message: '请填写密码' }]"
      />
    </van-cell-group>
    <div style="margin: 16px">
      <van-button round block type="primary" native-type="submit">
        登录
      </van-button>
    </div>
  </van-form>
</template>

<script setup>
import { ref,getCurrentInstance } from "vue";
const {proxy} = getCurrentInstance();
const username = ref("");
const password = ref("");
const onSubmit = (values) => {
  proxy.$AllRequest.login(values).then(res=>{
      if(res.data.code==2000){
          proxy.$Tools.showMessage(res.data.msg);
          proxy.$Tools.setToken(res.data.token);
          proxy.$router.push("/");
      }else {
          proxy.$Tools.showMessage(res.data.msg,"danger")
      }
  })
};
</script>

<style scoped>
</style>
